<?php

namespace app\home\model;

use think\Model;

class UsersignModel extends Model
{
    //消费者签到模型

    //连接数据表
    protected $table = 'by_user_sign';


    //获取消费者签到列表接口
    public static function getUserlist($uid)
    {
        return self::table('by_user_sign')->where('uid', $uid)->select()->toArray();
    }

    //查看用户连续签到几天
    public static function getUserday($uid)
    {
        return self::table('by_user_sign')->where('uid', $uid)->select()->count();
    }

    //用户签到超过7天后重新开始签到
    public static function deleteUserday($uid)
    {
        return self::table('by_user_sign')->where('uid', $uid)->delete();
    }

    //用户签到成功后添加数据
    public static function creatUserday($data)
    {
//        $data = [$uid, $integral, $last_time];
        return self::table('by_user_sign')->insert($data);
    }

    //查询今天的数据库的时间
    public static function findUserday($last_time)
    {
        return self::table('by_user_sign')->where('last_time', $last_time)->select();
    }

    //查看用户最后签到时间
    public static function oldUserday($uid)
    {
        return self::table('by_user_sign')->where('uid', $uid)
            ->order('last_time desc')->find()->toArray();
    }

}